package modelo.servicios;

import java.util.ArrayList;

import modelo.centrales.CentralElectrica;
import modelo.interfaces.Persistible;

public class RedElectrica implements Persistible {
        
    private CentralElectrica centralALaQuePertenece;
    private ArrayList<LineaDeTension> redDeLineasDeTension;
    
    public RedElectrica(CentralElectrica unaCentralElectrica)
    {
        this.centralALaQuePertenece = unaCentralElectrica;
        this.redDeLineasDeTension = new ArrayList<LineaDeTension>();
    }
    
    public CentralElectrica obtenerCentralALaQuePertenece()
    {
        return this.centralALaQuePertenece;
    }
    
    public boolean estaDaniada()
    {
        for (LineaDeTension lineaDeTension : this.redDeLineasDeTension)
        {
            if(lineaDeTension.estaDaniada())
            {
                return true;
            }                               
        }       
        return false;
    }

    public ArrayList<LineaDeTension> obtenerListaDeLineasDeTension()
    {
        return this.redDeLineasDeTension;
    }

	@Override
	public ArrayList obtenerDatosPersistibles()
	{
		ArrayList<Object> elems=new ArrayList<Object>();
		elems.add(redDeLineasDeTension);			
       	return elems;
	}

	@Override
	public void poblar(ArrayList elementos)
	{
		this.redDeLineasDeTension=(ArrayList<LineaDeTension>) elementos;
		for(LineaDeTension lineaDeTension : this.redDeLineasDeTension)
		{
			lineaDeTension.asignarRedElectrica(this);
		}
	}
}